/* Reset and base styles for consistent rendering across devices */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow: hidden;
    /* Responsive height - 450px in iframe, 90vh in new tab */
    height: 450px;
    width: 100%;
}

/* Detect if running in new tab vs iframe */
@media (min-height: 500px) {
    body {
        height: 90vh;
    }
}

/* Main game container with proper spacing and layout */
#gameContainer {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

/* Top progress and inventory bar - compact design */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: linear-gradient(90deg, #4CAF50, #45a049);
    color: white;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.progress-bar {
    width: 80px;
    height: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: #FFD700;
    width: 0%;
    transition: width 0.3s ease;
}

.inventory {
    font-size: 14px;
}

/* Main game area with flexible layout */
.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 10px;
    overflow: hidden;
}

/* Word section with image and target word */
.word-section {
    display: flex;
    align-items: center;
    gap: 15px;
    background: white;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    min-height: 60px;
}

.word-image {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f8ff;
    border-radius: 8px;
    border: 2px solid #ddd;
}

.image-placeholder {
    font-size: 24px;
}

.target-word {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    letter-spacing: 2px;
}

.word-progress {
    flex: 1;
    display: flex;
    gap: 2px;
    align-items: center;
}

.letter-slot {
    width: 25px;
    height: 30px;
    border: 2px solid #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    background: white;
    transition: all 0.3s ease;
}

.letter-slot.filled {
    background: #4CAF50;
    color: white;
    border-color: #45a049;
    transform: scale(1.1);
}

.letter-slot.current {
    border-color: #2196F3;
    background: #E3F2FD;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Sign language grid with responsive layout */
.sign-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(45px, 1fr));
    gap: 6px;
    padding: 5px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    overflow-y: auto;
    max-height: 200px;
}

/* Sign buttons with touch-friendly sizing */
.sign-btn {
    aspect-ratio: 1;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    transition: all 0.2s ease;
    min-height: 44px; /* Touch-friendly minimum size */
    position: relative;
    overflow: hidden;
}

.sign-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: #2196F3;
}

.sign-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.sign-btn.correct {
    background: #4CAF50;
    color: white;
    border-color: #45a049;
    animation: correctPulse 0.6s ease;
}

.sign-btn.incorrect {
    background: #f44336;
    color: white;
    border-color: #d32f2f;
    animation: shake 0.5s ease;
}

.sign-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

@keyframes correctPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); background: #66BB6A; }
    100% { transform: scale(1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.sign-image {
    width: 24px;
    height: 24px;
    margin-bottom: 2px;
    font-size: 18px;
}

/* Control buttons with compact design */
.controls {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.9);
    border-top: 1px solid #ddd;
}

.control-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: #2196F3;
    color: white;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 36px;
    white-space: nowrap;
}

.control-btn:hover {
    background: #1976D2;
    transform: translateY(-1px);
}

.control-btn:active {
    transform: translateY(0);
}

.control-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Dialogue box for feedback and instructions */
.dialogue-box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    max-width: 280px;
    width: 90%;
}

.dialogue-content {
    padding: 20px;
    text-align: center;
}

.dialogue-content p {
    margin-bottom: 15px;
    font-size: 14px;
    line-height: 1.4;
}

.dialogue-close {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    background: #4CAF50;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s ease;
}

.dialogue-close:hover {
    background: #45a049;
}

/* Celebration overlay for achievements */
.celebration {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
}

.celebration-content {
    background: white;
    padding: 30px;
    border-radius: 16px;
    text-align: center;
    animation: celebrationPop 0.6s ease;
}

.celebration-content h2 {
    color: #4CAF50;
    margin-bottom: 10px;
    font-size: 20px;
}

.celebration-content p {
    margin-bottom: 15px;
    font-size: 14px;
}

.treasure-icon {
    font-size: 48px;
    animation: bounce 1s infinite;
}

@keyframes celebrationPop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Tooltip styling for accessibility */
[title] {
    position: relative;
}

/* Mobile responsiveness and touch optimization */
@media (max-width: 480px) {
    .sign-grid {
        grid-template-columns: repeat(6, 1fr);
        gap: 4px;
    }
    
    .sign-btn {
        min-height: 40px;
        font-size: 9px;
    }
    
    .word-section {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }
    
    .target-word {
        font-size: 16px;
    }
}

/* High contrast mode for accessibility */
@media (prefers-contrast: high) {
    .sign-btn {
        border-width: 3px;
    }
    
    .letter-slot {
        border-width: 3px;
    }
}